package task

import (
	"GoPro/Server/msgProto"
	"GoPro/Server/mynet"
	"GoPro/Server/protoMsg"
	"encoding/binary"
	"fmt"
	"google.golang.org/protobuf/proto"
)

type GetRoomUserRouter struct {
}

func (msg *GetRoomUserRouter) PreHandler(req mynet.IRequest) bool {
	_, ok := req.GetServer().OnlineUser[req.GetIConnection()]
	if !ok {
		return false
	}
	room := req.GetServer().ManagerRoom.GetRoomUsers("929917283", "929917283")
	header := msgProto.MsgHeader{}
	header.MsgType = 1
	users := protoMsg.RoomUsers{}
	for _, userRoom := range room {
		users.Usernumber = append(users.Usernumber, userRoom)
	}
	marshal, err := proto.Marshal(&users)
	fmt.Println(err)
	header.MsgSize = int32(len(marshal))
	binary.Write(req.GetIConnection().GetWriter(), binary.BigEndian, header)
	binary.Write(req.GetIConnection().GetWriter(), binary.BigEndian, marshal)
	return true
}

func (msg *GetRoomUserRouter) Handler(req mynet.IRequest) bool {
	return true
}

func (msg *GetRoomUserRouter) PostHandler(req mynet.IRequest) bool {
	return true
}
